#!/bin/bash
#wget -q -O - http://59.83.33.68/idrac.sh|bash -
function chkracadm(){
	rpm -qa|grep racadm &>/dev/null
	if [ "$?" = "0" ];then
		configracadm
	else
		installracadm
	fi
}

function configracadm(){
	IP=$(ip a|grep 192.168|head -1|awk '{print $2}'|awk -F "/" '{print $1}')
	IP1=$(echo $IP|awk -F "." '{print $3}')
	IP2=$(echo $IP|awk -F "." '{print $4}')
	(( IP2 = $IP2 + 100 ))
	IP4=$(echo 192.168.$IP1.$IP2)
	IP3=$(racadm getconfig -g cfgLanNetworking|grep cfgNicIpAddress|awk -F "=" '{print $2}')
	if [ "$IP4" = "$IP3" ];then
	displayracadm
	else
	racadm config -g cfgLanNetworking -o cfgNicSelection 0 &>/dev/null
	racadm setniccfg -s 192.168.$IP1.$IP2 255.255.255.0 192.168.$IP1.1 &>/dev/null
	racadm config -g cfgUserAdmin -o cfgUserAdminPassword -i 2 c218m571y &>/dev/null
	displayracadm
	fi
	unset IP
	unset IP1
	unset IP2
	unset IP3
	unset IP4
}

function displayracadm(){
	echo Server IP is $IP
	racadm getconfig -g cfgLanNetworking|grep cfgNicIpAddress
	racadm getconfig -g cfgLanNetworking|grep cfgDNSRacName
}

function installracadm(){
	RELEASEVER=$(rpm -qi centos-release|grep Version|awk '{print $3}')
	if [ "$RELEASEVER" = "6" ];then
		yum -q -y install wget
		rm /etc/yum.repos.d/* -rf
		wget -q -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.upnet.cn/centos/Centos-6.repo
		wget -q -O /etc/yum.repos.d/dell-omsa-repository.repo http://mirrors.upnet.cn/dell/dell-omsa-repository6.repo 
		yum -q clean all
		yum -q makecache
		yum -q -y install perl
		yum -q -y install srvadmin-all
		/opt/dell/srvadmin/sbin/srvadmin-services.sh start &>/dev/null
		ln -s /opt/dell/srvadmin/sbin/racadm /bin/racadm &>/dev/null
		ln -s /opt/dell/srvadmin/sbin/racadm /sbin/racadm &>/dev/null
		source /etc/profile &>/dev/null
		configracadm
	else
	echo -e "Your SYSTEM is not Centos-6! exit!"
	exit 1;
	fi
	unset RELEASEVER
}

function uninstallracadm(){
	yum -q -y remove srvadmin*
	rm /opt/dell/srvadmin/ -rf
}

chkracadm


#racadm setniccfg -s 192.168.143.102 255.255.255.0 192.168.143.1